package cn.xkai.exercise.b;

/**
 * @description: 3的幂
 * <p>
 * 自己的思路：暴力循环
 * 借鉴的思路：算术法、极值法
 * @author: kaixiang
 * @date: 2022-07-14
 **/
public class Solution58 {
    public boolean isPowerOfThree(int n) {
        while (n > 1) {
            if (n % 3 > 0) {
                return false;
            }
            n /= 3;
        }
        return n == 1;
    }

    public boolean isPowerOfThreeExp(int n) {
        return (Math.log10(n) / Math.log10(3)) % 1 == 0;
    }

    public boolean isPowerOfThreeMax(int n) {
        return (n > 0 && 1162261467 % n == 0);
    }
}
